home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995 August: Tool Chest / Dev.CD Aug 95 TC / Dev.CD Aug 95 TC.toast / Sample Code / Snippets / Toolbox / ItemHider / Turbo / MultiHider / MultiHider.Pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1992-07-15  |  3.3 KB  |  132 lines  |  [TEXT/TPAS]

  1. PROGRAM MultiHider;
  2.  
  3. {$R MultiHider.Rsrc}
  4. {$U-}
  5.  
  6. USES Memtypes,QuickDraw,OSIntf,ToolIntf,PackIntf;
  7.  
  8. CONST
  9.    itemOK =       7;
  10.    itemCancel =   8;
  11.    itemStat1 =    1;
  12.    itemStat2 =    3;
  13.    itemStat3 =    4;
  14.    itemEdit1 =    2;
  15.    itemEdit2 =    5;
  16.    itemEdit3 =    6;
  17.    itemHider =    9;
  18.    itemHideIt =   10;
  19.    itemMax =      10;
  20. VAR
  21.    ihDialog:   DialogPtr;
  22.    itemHit:    INTEGER;
  23.    theType:    INTEGER;
  24.    theHdl:     Handle;
  25.    theBox:     Rect;  
  26.    hidden:     BOOLEAN;
  27.  
  28.  
  29. PROCEDURE MyDrawItem(dlg: DialogPtr; theItem: INTEGER);
  30. VAR
  31.    iType:   INTEGER;
  32.    iBox:    Rect;
  33.    iHdl:    Handle;
  34.    iIndex:  INTEGER;
  35.  
  36. BEGIN
  37.    GetDItem(dlg, theItem, iType, iHdl, iBox);
  38.    IF hidden THEN BEGIN
  39.       PenMode(notPatBic);
  40.       PenPat(gray);
  41.       BackPat(gray);
  42.       PaintRect(iBox);
  43.       FrameRect(iBox);
  44.       
  45.       PenMode(patCopy);
  46.       PenPat(black);
  47.       BackPat(white);
  48.       PenNormal;
  49.    END;
  50. END;
  51.  
  52.  
  53. PROCEDURE HideEditItem(theDialog: DialogPtr; theItem: INTEGER);
  54. VAR
  55.    iIndex:  INTEGER;
  56. BEGIN
  57.    (* Get the item information. *)
  58.    GetDItem(theDialog, theItem, theType, theHdl, theBox);
  59.    
  60.    (* Now check to see if it is the current text item.   *)
  61.    IF DialogPeek(theDialog)^.EditField + 1 = theItem THEN BEGIN
  62.       (* It is, so now we find the next editText item    *)
  63.       (* in the item list.  Start with the one we are on.*)
  64.       iIndex := theItem;
  65.       REPEAT
  66.          (* Increment to the next item, and make sure we *)
  67.          (* don't run off the end of the item list.      *)
  68.          iIndex := iIndex + 1;
  69.          IF iIndex > itemMax THEN iIndex := 1;
  70.          GetDItem(theDialog, iIndex, theType, theHdl, theBox);
  71.  
  72.          (* Keep going until we find an editText item.   *)
  73.          (* NOTE: THIS CODE ASSUMES THERE IS MORE THAN   *)
  74.          (*       ONE editText ITEM IN THE DIALOG.       *)
  75.       UNTIL (theType = editText);
  76.       SelIText(theDialog, iIndex, 0, 0);
  77.    END;
  78.    GetDItem(theDialog, theItem, theType, theHdl, theBox);
  79.    SetDItem(theDialog, theItem, statText, theHdl, theBox);
  80.    DrawDialog(theDialog);
  81. END;
  82.  
  83.  
  84. PROCEDURE ShowEditItem(theDialog: DialogPtr; theItem: INTEGER);
  85. VAR
  86.    oldPort: GrafPtr;
  87. BEGIN
  88.    GetPort(oldPort);
  89.    SetPort(theDialog);
  90.    GetDItem(theDialog, theItem, theType, theHdl, theBox);
  91.    SetDItem(theDialog, theItem, editText, theHdl, theBox);
  92.    InvalRect(theBox);
  93.    DrawDialog(theDialog);
  94.    SetPort(oldPort);
  95. END;
  96.  
  97.  
  98. BEGIN {main program}
  99.    InitGraf (@thePort);          {the big five inits}
  100.    InitFonts;
  101.    InitWindows;
  102.    TEInit;
  103.    InitDialogs (nil);
  104.  
  105.    hidden := FALSE;
  106.  
  107.    ihDialog := GetNewDialog(128, NIL, WindowPtr(-1));
  108.    GetDItem(ihDialog, itemHider, theType, theHdl, theBox);
  109.    SetDItem(ihDialog, itemHider, theType, @MyDrawItem, theBox);
  110.    ShowWindow(ihDialog);
  111.    
  112.    itemHit := 0;
  113.    WHILE ((itemHit <> itemOK) AND (itemHit <> itemCancel)) DO BEGIN
  114.       ModalDialog(nil, itemHit);
  115.       CASE itemHit OF
  116.          itemHideIt: BEGIN
  117.             GetDItem(ihDialog, itemHit, theType, theHdl, theBox);
  118.             hidden := NOT hidden;
  119.             IF hidden THEN BEGIN
  120.                SetCtlValue(ControlHandle(theHdl), 1);
  121.                HideEditItem(ihDialog, itemEdit2);
  122.             END ELSE BEGIN
  123.                SetCtlValue(ControlHandle(theHdl), 0);
  124.                ShowEditItem(ihDialog, itemEdit2);
  125.             END;
  126.          END;
  127.       END;
  128.    END;
  129.  
  130.    DisposDialog(ihDialog);
  131. END.
  132.